package ordercode;

import java.util.Arrays;

public class QuickOrder {
    public static void main(String[] args) {
        int[] arr = {6,5,34,12,23,67,13};
        quickSort(arr,0,arr.length-1);
        System.out.println(Arrays.toString(arr));
    }
    public static void quickSort(int[] arr,int i,int j){
        int start = i;
        int end = j;
        if(start>end){
            return;
        }
        int baseNumber = arr[i];
        while (end != start){
            // end的交换操作
            while (true){
                if(end<=start || arr[end] < baseNumber){
                    break;
                }
                end--;
            }
            // start的交换操作
            while (true){
                if(end<=start || arr[start] > baseNumber){
                    break;
                }
                start++;
            }
            int temp = arr[i];
            arr[i] = arr[start];
            arr[start] = temp;
        }
        quickSort(arr,0,start-1);
        quickSort(arr,start+1,j);

    }

    // 函数递归练习一：递加
    public static int recursion(int number){
        if(number ==1){
            return 1;
        }else {
            return number + recursion(number-1);
        }
    }
    // 函数递归练习二: 递归
    public static int factories(int number){
        if(number==1){
            return 1;
        }else {
            return number*factories(number-1);
        }
    }
}
